package com.lysj.admin.master.bussiness.company.invoice.controller;

import com.lysj.admin.master.bussiness.admin.domain.ServiceProvider;
import com.lysj.admin.master.bussiness.admin.service.ServiceProviderService;
import com.lysj.admin.master.bussiness.company.company.dto.CompanyBaseDto;
import com.lysj.admin.master.bussiness.company.invoice.domain.InvoiceApply;
import com.lysj.admin.master.bussiness.company.invoice.domain.InvoiceInfo;
import com.lysj.admin.master.bussiness.company.invoice.mapper.InvoiceApplyMapper;
import com.lysj.admin.master.bussiness.company.invoice.service.InvoiceApplyService;
import com.lysj.admin.master.bussiness.company.invoice.service.InvoiceInfoService;
import com.lysj.admin.master.common.CommonConstant;
import com.lysj.admin.master.common.annotation.MyList;
import com.lysj.admin.master.common.spring.mpbase.MyController;
import com.lysj.admin.master.common.spring.mpbase.MyService;
import com.lysj.admin.master.common.spring.pagination.PageRequestDTO;
import com.lysj.admin.master.common.web.Resp;
import com.lysj.admin.master.common.web.RespUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Created by drj on 2020-01-07 20:59
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/company/invoice_apply")
public class InvoiceApplyController extends MyController<InvoiceApplyMapper, InvoiceApply, PageRequestDTO> {

    @Resource
    private InvoiceApplyService invoiceApplyService;
    @Resource
    private ServiceProviderService serviceProviderService;
    @Resource
    private InvoiceInfoService invoiceInfoService;

    @Override
    public MyService<InvoiceApplyMapper, InvoiceApply> getService() {
        return invoiceApplyService;
    }

    @MyList
    public Resp list(CompanyBaseDto condition) {
        //获取当前登录代理商
        String companyId = getJwtProperty(CommonConstant.COMPANY_ID_NAME);
        condition.setCompanyId(companyId);
        return super.list(condition);
    }

    /*
     * @author Created by drj on 2020/1/8 17:37
     * @Description :获取用工企业开票信息和服务商信息
     */
    @GetMapping("/invoice_and_ser")
    public Resp invoiceAndSer(String serviceProviderId, String companyId) {
        Map<String, Object> map = new HashMap<>();
        //获取服务商信息
        ServiceProvider serviceProvider = serviceProviderService.getById(serviceProviderId);
        //获取开票信息
        InvoiceInfo invoiceInfo = invoiceInfoService.findByCompanyId(companyId);
        map.put("serviceProvider", serviceProvider);
        map.put("invoiceInfo", invoiceInfo);
        return RespUtil.success(map);
    }
}
